package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.Payment;
import com.vne.skyemart.service.PaymentService;

@Controller
@SessionAttributes
@RequestMapping("/payment")
public class PaymentController {

	@Autowired
	private PaymentService paymentService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView savePayment(@ModelAttribute(" payment") Payment payment,
			BindingResult result) {
		 paymentService.addPayment(payment);
		return new ModelAndView("redirect:/payment.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listPayment(Model model) {
		model.addAttribute("payment",  paymentService.listPayment());

		return "paymentList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addPayment(@ModelAttribute("payment") Payment payment,
			BindingResult result) {
		return new ModelAndView("addPayment");
	}

}